<template>
  <div class="yh_content foSi14">
    <div class="tback">
      <el-button type="primary" class="bac6b7" @click="back">返回列表</el-button>
    </div>
    <div class="contents">
      <div class="small_title">卡信息</div>
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules">
        <div class="forms">
          <div class="forms_item">
            <div class="left_title"><span style="color:red;margin-right:2px">*</span>会员卡种类</div>
            <el-form-item class="mp0" prop="name">
              <el-input v-model="ruleForm.name" size="small" placeholder="会员卡种类" />
            </el-form-item>
          </div>
          <div v-if="!id" class="forms_item">
            <div class="left_title">会员卡类型</div>
            <el-select
              v-model="ruleForm.card_type"
              placeholder="请选择"
              size="small"
              style="width:185px"
              @change="cardTypeChange"
            >
              <el-option
                v-for="item in cardtypelist"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </div>
          <div v-if="id" class="forms_item">
            <div class="left_title">会员卡类型</div>
            <div>{{ ruleForm.card_type == 1 ? '期限卡' : ruleForm.card_type == 2 ? '次数卡' : '储值卡' }}</div>
          </div>
          <div v-if="type == 0" class="forms_item">
            <div class="left_title"><span style="color:red;margin-right:2px">*</span>售价</div>
            <el-form-item class="mp0" prop="sell_price">
              <el-input v-model="ruleForm.sell_price" size="small" placeholder="请输入售价" />
            </el-form-item>
          </div>
          <div v-if="type == 0" class="forms_item">
            <div class="left_title"><span style="color:red;margin-right:2px">*</span>市场价</div>
            <el-form-item class="mp0" prop="market_price">
              <el-input v-model="ruleForm.market_price" size="small" placeholder="请输入市场价" />
            </el-form-item>
          </div>
          <div v-if="type == 0" class="forms_item">
            <div class="left_title">成本价</div>
            <el-form-item class="mp0" prop="cost_price">
              <el-input v-model="ruleForm.cost_price" size="small" placeholder="成本价" />
            </el-form-item>
          </div>
          <div v-if="type == 0" class="forms_item">
            <div class="left_title">是否上架</div>
            <el-select v-model="ruleForm.status" style="width:185px">
              <el-option
                v-for="item in statusList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </div>
          <div class="forms_item">
            <div class="left_title"><span style="color:red;margin-right:2px">*</span>有效期</div>
            <div class="dis disAl">
              <el-form-item class="mp0" prop="card_period">
                <el-input
                  v-model="ruleForm.card_period"
                  style="width: 87px"
                  size="small"
                  placeholder="有效期"
                />
              </el-form-item>
              <div style="margin-left: 10px">
                <el-select
                  v-model="ruleForm.card_period_type"
                  placeholder="请选择"
                  size="small"
                  style="width:87px"
                >
                  <el-option
                    v-for="item in timetypelist"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </div>
            </div>
          </div>
          <div v-if="ruleForm.card_type !== 1" class="forms_item">
            <div class="left_title"><span
              style="color:red;margin-right:2px"
            >*</span>卡额度({{ ruleForm.card_type===2?'次':'元' }})
            </div>
            <el-form-item class="mp0" prop="card_money">
              <el-input v-model="ruleForm.card_money" size="small" placeholder="卡额度" />
            </el-form-item>
          </div>
          <div class="forms_item">
            <div class="left_title"><span style="color:red;margin-right:2px">*</span>库存</div>
            <div class="dis disAl">
              <el-form-item class="mp0" prop="card_money">
                <el-input v-model="ruleForm.stock" size="small" placeholder="卡库存" />
              </el-form-item>
            </div>
          </div>
          <div class="forms_item" />
          <div v-if="ruleForm.card_type === 1" class="forms_item" />
          <div class="wid100 forms_item3 dis disAl disJuB">
            <div class="left_title">卖点</div>
            <el-input v-model="ruleForm.sellpoint" type="textarea" class="wid87" placeholder="请输入卖点" />
          </div>
          <div v-if="type == 0" class="wid100 forms_item3">
            <div class="dis disAl">
              <div class="left_title" style="min-width: 130px;">分销设置</div>
              <div class="dis disAl flwa">
                <div
                  v-for="(item,index) in commissionsetList"
                  :key="index"
                  class="dis disAl hei32 cuPo mar-right20"
                  @click.stop="ruleForm.commissionset = item.value"
                >
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  >
                    <div
                      v-if="ruleForm.commissionset === item.value"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">{{ item.label }}</div>
                </div>
              </div>
            </div>
            <div class="layui-word-aux">
              按照会员等级：按照会员等级中设置的提成比例进行提成分配，提成=对应会员等级的提成比例×销售价×购买数量<br>
              单独设置提成比例：按照单独设置的提成比例进行提成分配，提成=设置的百分比×销售价×购买数量<br>
              单独设置提成金额：按照单独设置的提成金额进行提成分配，提成=提成金额×购买数量<br>
              分销送积分：分销提成不给佣金而是给积分，得到的积分=提成积分×购买数量<br>
              * 当商家开启独立收款并且开启商家返款扣除分销佣金时，提成金额比例+平台抽成金额比例不能超过30%（微信支付分账限制）
            </div>
          </div>
          <div
            v-for="(item, index) in levellist"
            v-if="ruleForm.commissionset === 1 || ruleForm.commissionset === 5"
            :key="index+'a'"
            class="wid100 forms_item3 dis disAl"
          >
            <div class="left_title" style="width: 130px;">{{ item.name }}</div>
            <div v-if="item.can_agent === 0" class="dis disAl hei32" style="color: #e84577;">暂未不支持分销</div>
            <div v-if="item.can_agent > 0" class="dis disAl">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 一级(%) </div>
              <el-input
                v-model="ruleForm[item.b_one]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="item.can_agent > 1" class="dis disAl mar-left20">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 二级(%) </div>
              <el-input
                v-model="ruleForm[item.b_two]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="item.can_agent > 2" class="dis disAl mar-left20">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 三级(%) </div>
              <el-input
                v-model="ruleForm[item.b_three]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
          </div>
          <div
            v-for="(item, index) in levellist"
            v-if="ruleForm.commissionset === 2 || ruleForm.commissionset === 6"
            :key="index+'b'"
            class="wid100 forms_item3 dis disAl"
          >
            <div class="left_title" style="width: 130px;">{{ item.name }}</div>
            <div v-if="item.can_agent === 0" class="dis disAl hei32" style="color: #e84577;">暂未不支持分销</div>
            <div v-if="item.can_agent > 0" class="dis disAl">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 一级(元) </div>
              <el-input
                v-model="ruleForm[item.one_money]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="item.can_agent > 1" class="dis disAl mar-left20">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 二级(元) </div>
              <el-input
                v-model="ruleForm[item.two_money]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="item.can_agent > 2" class="dis disAl mar-left20">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 三级(元) </div>
              <el-input
                v-model="ruleForm[item.three_money]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
          </div>
          <div
            v-for="(item, index) in levellist"
            v-if="ruleForm.commissionset === 3 || ruleForm.commissionset === 5 || ruleForm.commissionset === 6"
            :key="index+'c'"
            class="wid100 forms_item3 dis disAl"
          >
            <div class="left_title" style="width: 130px;">{{ item.name }}</div>
            <div v-if="item.can_agent === 0" class="dis disAl hei32" style="color: #e84577;">暂未不支持分销</div>
            <div v-if="item.can_agent > 0" class="dis disAl">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 一级(积分) </div>
              <el-input
                v-model="ruleForm[item.j_one]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="item.can_agent > 1" class="dis disAl mar-left20">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 二级(积分) </div>
              <el-input
                v-model="ruleForm[item.j_two]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="item.can_agent > 2" class="dis disAl mar-left20">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> 三级(积分) </div>
              <el-input
                v-model="ruleForm[item.j_three]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
          </div>
          <div class="wid100 forms_item3">
            <div class="dis disAl">
              <div style="width: 130px;">卡主图</div>
              <el-upload
                action="#"
                :http-request="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
                class="upImg1"
              >
                <div class="que coFFF">上传图片</div>
              </el-upload>
              <div class="goods-imgs__tips foSi12 mar-left10">建议尺寸：640*420像素</div>
            </div>
            <div class="dis disAl mar-top10">
              <div style="width: 130px;" />
              <div style="width: 104px;height: 104px;background-color: #f6f6f6;">
                <img v-if="ruleForm.pic" :src="ruleForm.pic" class="wh100"></img>
              </div>
            </div>
            <div class="dis disAl mar-top20">
              <div style="width: 130px;">卡图片</div>
              <el-upload
                class="upImg1"
                action="#"
                :http-request="handleAvatarSuccess1"
                multiple
                :before-upload="beforeAvatarUpload"
              >
                <div class="que coFFF">上传图片</div>
              </el-upload>
              <div class="goods-imgs__tips foSi12 mar-left10">建议尺寸：640*420像素</div>
            </div>
            <div class="dis disAl mar-top10">
              <div style="min-width: 130px;" />
              <div class="dis disAl flwa">
                <div
                  v-for="(item,index) in ruleForm.pics"
                  :key="index"
                  class="poRel mar-right20 mar-bott15"
                  style="width: 104px;height: 104px;background-color: #f6f6f6;"
                >
                  <svg-icon
                    icon-class="guanbi"
                    class="mar0 poAbs cuPo"
                    style="color: #000;width: 20px;height: 20px; top: -10px;right: -10px;z-index: 10;"
                    @click.stop="deletePics(index)"
                  />
                  <img :src="item" class="wh100"></img>
                </div>
              </div>
            </div>
          </div>
          <div v-if="type == 0" class="wid100 forms_item3">
            <div class="dis disAl">
              <div class="left_title" style="min-width: 130px;">分红设置</div>
              <div class="dis disAl">
                <div class="dis disAl hei32 cuPo mar-right20" @click.stop="ruleForm.fenhongset = 1">
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  >
                    <div
                      v-if="ruleForm.fenhongset === 1"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">参与</div>
                </div>
                <div class="dis disAl hei32 cuPo mar-right5" @click.stop="ruleForm.fenhongset = 0">
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  >
                    <div
                      v-if="ruleForm.fenhongset === 0"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">不参与</div>
                </div>
              </div>
            </div>
          </div>
          <div v-if="ruleForm.fenhongset === 1" class="wid100 forms_item3">
            <div class="dis disAl">
              <div class="left_title" style="min-width: 130px;">团队分红</div>
              <div class="dis disAl flwa">
                <div
                  v-for="(item,index) in fenhongsetList"
                  :key="index"
                  class="dis disAl hei32 cuPo mar-right20"
                  @click.stop="ruleForm.teamfenhongset = item.value"
                >
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  >
                    <div
                      v-if="ruleForm.teamfenhongset === item.value"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">{{ item.label }}</div>
                </div>
              </div>
            </div>
            <div class="layui-word-aux">开启后可以拿到团队中所有会员的所有商城订单的分红金额或比例，请先在[会员]-[等级及分销]设置分红级数</div>
          </div>
          <div
            v-if="ruleForm.fenhongset === 1 && (ruleForm.teamfenhongset === 1 || ruleForm.teamfenhongset === 2)"
            class="wid100 forms_item3 dis disAl"
          >
            <div class="left_title" style="width: 130px;">分红比例</div>
            <div
              v-for="(item, index) in levellist"
              v-if="ruleForm.teamfenhongset === 1 && item.teamfenhonglv > 0"
              :key="index+'d'"
              class="dis disAl mar-right20"
            >
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> {{ item.name }}(%)
              </div>
              <el-input
                v-model="ruleForm[item.teamfenhongset1]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div
              v-for="(item, index) in levellist"
              v-if="ruleForm.teamfenhongset === 2 && item.teamfenhonglv > 0"
              :key="index+'d'"
              class="dis disAl mar-right20"
            >
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> {{ item.name }}(元)
              </div>
              <el-input
                v-model="ruleForm[item.teamfenhongset2]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="!teamfenhonglv" class="hei32 dis disAl" style="color: #ff0000;">
              未设置具有团队分红权限的会员等级，请先在[会员]-[等级及分销]设置</div>
          </div>
          <div v-if="ruleForm.fenhongset === 1" class="wid100 forms_item3">
            <div class="dis disAl">
              <div class="left_title" style="min-width: 130px;">股东分红</div>
              <div class="dis disAl flwa">
                <div
                  v-for="(item,index) in fenhongsetList"
                  :key="index"
                  class="dis disAl hei32 cuPo mar-right20"
                  @click.stop="ruleForm.gdfenhongset = item.value"
                >
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  >
                    <div
                      v-if="ruleForm.gdfenhongset === item.value"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">{{ item.label }}</div>
                </div>
              </div>
            </div>
            <div class="layui-word-aux">用于股东分红或合伙人分红，开启后相应等级的所有会员平均分摊设置的分红金额或比例</div>
          </div>
          <div
            v-if="ruleForm.fenhongset === 1 && (ruleForm.gdfenhongset === 1 || ruleForm.gdfenhongset === 2)"
            class="wid100 forms_item3 dis disAl"
          >
            <div class="left_title" style="width: 130px;">分红比例</div>
            <div
              v-for="(item, index) in levellist"
              v-if="ruleForm.gdfenhongset === 1 && item.fenhong > 0"
              :key="index+'d'"
              class="dis disAl mar-right20"
            >
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> {{ item.name }}(%)
              </div>
              <el-input
                v-model="ruleForm[item.gdfenhongset1]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div
              v-for="(item, index) in levellist"
              v-if="ruleForm.gdfenhongset === 2 && item.fenhong > 0"
              :key="index+'d'"
              class="dis disAl mar-right20"
            >
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> {{ item.name }}(元)
              </div>
              <el-input
                v-model="ruleForm[item.gdfenhongset2]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="!fenhong" class="hei32 dis disAl" style="color: #ff0000;">
              未设置具有股东分红权限的会员等级，请先在[会员]-[等级及分销]设置</div>
          </div>
          <div v-if="ruleForm.fenhongset === 1" class="wid100 forms_item3">
            <div class="dis disAl">
              <div class="left_title" style="min-width: 130px;">区域代理分红</div>
              <div class="dis disAl flwa">
                <div
                  v-for="(item,index) in fenhongsetList"
                  :key="index"
                  class="dis disAl hei32 cuPo mar-right20"
                  @click.stop="ruleForm.areafenhongset = item.value"
                >
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  >
                    <div
                      v-if="ruleForm.areafenhongset === item.value"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">{{ item.label }}</div>
                </div>
              </div>
            </div>
            <div class="layui-word-aux">设置分红比例或分红金额后该等级的同一个代理区域的人平均分摊所有商城内该区域的订单的分红提成比例或分红金额</div>
          </div>
          <div
            v-if="ruleForm.fenhongset === 1 && (ruleForm.areafenhongset === 1 || ruleForm.areafenhongset === 2)"
            class="wid100 forms_item3 dis disAl"
          >
            <div class="left_title" style="width: 130px;">分红比例</div>
            <div
              v-for="(item, index) in levellist"
              v-if="ruleForm.areafenhongset === 1 && item.areafenhongbl > 0"
              :key="index+'d'"
              class="dis disAl mar-right20"
            >
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> {{ item.name }}(%)
              </div>
              <el-input
                v-model="ruleForm[item.areafenhongset1]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div
              v-for="(item, index) in levellist"
              v-if="ruleForm.areafenhongset === 2 && item.areafenhongbl > 0"
              :key="index+'d'"
              class="dis disAl mar-right20"
            >
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;"> {{ item.name }}(元)
              </div>
              <el-input
                v-model="ruleForm[item.areafenhongset2]"
                size="small"
                class="fenxiao"
                style="width: 100px;"
                @input="ruleFormChange"
              />
            </div>
            <div v-if="!areafenhongbl" class="hei32 dis disAl" style="color: #ff0000;">
              未设置具有区域代理分红权限的会员等级，请先在[会员]-[等级及分销]设置</div>
          </div>
          <div v-if="type == 0" class="wid100 forms_item3 dis disAl">
            <div class="left_title" style="min-width: 130px;">积分抵扣设置</div>
            <div class="dis disAl flwa">
              <div
                v-for="(item,index) in scoredkmaxList"
                :key="index"
                class="dis disAl hei32 cuPo mar-right20"
                @click.stop="ruleForm.scoredkmaxset = item.value"
              >
                <div
                  class="dis disAl disJuC bacFFF borRad50"
                  style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                >
                  <div
                    v-if="ruleForm.scoredkmaxset === item.value"
                    class="borRad50"
                    style="width: 6px;height: 6px;background: #41c3a8;"
                  />
                </div>
                <div class="mar-left5">{{ item.label }}</div>
              </div>
            </div>
          </div>
          <div
            v-if="ruleForm.scoredkmaxset === 1 || ruleForm.scoredkmaxset === 2"
            class="wid100 forms_item3 dis disAl"
          >
            <div style="width: 130px;" />
            <div class="dis disAl">
              <div class="hei32 dis disAl" style="background: #e6e6e6;padding: 0 9px;">
                最多抵扣({{ ruleForm.scoredkmaxset === 1?'%':'元' }}) </div>
              <el-input
                v-model="ruleForm.scoredkmaxval"
                size="small"
                class="fenxiao"
                style="width: 100px;"
              />
            </div>
          </div>
          <div class="forms_item2 wid100">
            <div class="hei20 dis disAl" style="font-size: 14px;margin-top: 10px;line-height: 20px">适用课程
            </div>
            <div class="foSi14" style="margin-left: 120px;">
              <!-- <el-tree :data="data" show-ch0eckbox size="mini" default-expand-all="true" node-key="id"
                :default-expanded-keys="[2, 3]" style="background: #ededed;" :default-checked-keys="[5]"
                :props="defaultProps" /> -->
              <div v-for="(item2,index2) in treeList" :key="index2">
                <div class="hei34 mar-bott5 dis disAl">
                  <i
                    :class="item2.tr?'el-icon-caret-bottom':'el-icon-caret-right'"
                    class="cuPo mar-right10"
                    size="14px"
                    @click.stop="item2.tr = !item2.tr"
                  />
                  <el-checkbox v-model="item2.is_support" @change="treeChange(index2,0,0,0)" />
                  <span class="mar-left10 cuPo">{{ item2.name }}</span>
                </div>
                <div
                  v-for="(item,index) in item2.children"
                  v-if="item2.tr"
                  :key="index"
                  style="padding-left: 26px;"
                >
                  <div class="hei34 mar-bott5 dis disAl">
                    <i
                      :class="item.tr?'el-icon-caret-bottom':'el-icon-caret-right'"
                      class="cuPo mar-right10"
                      size="14px"
                      @click.stop="item.tr = !item.tr"
                    />
                    <el-checkbox v-model="item.is_support" @change="treeChange(index2,index,0,1)" />
                    <span class="mar-left10 cuPo">{{ item.name }}</span>
                  </div>
                  <div
                    v-if="item.tr && ruleForm.card_type === 1"
                    class="dis disAl flwa"
                    style="padding-left: 26px;"
                  >
                    <div
                      v-for="(item1,index1) in item.children"
                      :key="index1"
                      class="hei34 mar-bott5 dis disAl mar-left20"
                    >
                      <el-checkbox
                        v-model="item1.is_support"
                        @change="treeChange(index2,index,index1,2)"
                      />
                      <span class="mar-left10">{{ item1.coach_name }} / {{ item1.name }}</span>
                    </div>
                  </div>
                  <div
                    v-for="(item1,index1) in item.children"
                    v-if="item.tr && ruleForm.card_type !== 1"
                    :key="index1"
                    class="hei34 mar-bott5 dis disAl mar-left20"
                    style="padding-left: 26px;"
                  >
                    <el-checkbox
                      v-model="item1.is_support"
                      @change="treeChange(index2,index,index1,2)"
                    />
                    <span class="mar-left10">{{ item1.coach_name }} / {{ item1.name }}</span>
                    <span class="mar-left5 mar-right5"> 每节课收费 </span>
                    <el-form-item :prop="`${item1.course_id}`" :rules="rules.value" class="mp0">
                      <el-input
                        v-if="ruleForm.card_type === 2"
                        v-model="item1.frequency"
                        size="small"
                        placeholder="请输入次数"
                        style="width: 140px;"
                        @blur="cardAppChange(index2,index,index1)"
                      />
                    </el-form-item>
                    <el-form-item :prop="`${item1.course_id}`" :rules="rules.value1" class="mp0">
                      <el-input
                        v-if="ruleForm.card_type === 3"
                        v-model="item1.frequency"
                        size="small"
                        placeholder="请输入费用"
                        style="width: 140px;"
                        @blur="cardAppChange(index2,index,index1)"
                      />
                    </el-form-item>
                    <span class="mar-left5"> {{ ruleForm.card_type === 2?'次':'元' }}/人</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div v-if="type == 0" class="wid100 forms_item3 foSi14">
            <div class="hei32 dis disAl">购卡赠积分</div>
            <div class="dis disAl" style="padding: 8px 15px 20px 150px;">
              <div>赠送积分</div>
              <div class="mar-left30">
                <el-form-item class="mp0" prop="card_give_integral">
                  <el-input v-model="ruleForm.card_give_integral" size="small" placeholder="请输入积分" />
                </el-form-item>
              </div>
              <div class="mar-left5">分</div>
            </div>
          </div>
          <div v-if="ruleForm.card_type === 1" class="wid100 forms_item3 foSi14">
            <div class="hei32 dis disAl">赠送积分设置</div>
            <div style="padding: 0 0 5px 150px;">
              <div class="dis disAl cuPo">
                <div
                  class="dis disAl disJuC bacFFF borRad50"
                  style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  @click.stop="ruleForm.card_give_integral_type = 1"
                >
                  <div
                    v-if="ruleForm.card_give_integral_type === 1"
                    class="borRad50"
                    style="width: 6px;height: 6px;background: #41c3a8;"
                  />
                </div>
                <div class="mar-left5">使用该卡约课/签到时不赠送积分</div>
              </div>
              <div class="dis disAl cuPo mar-top10">
                <div
                  class="dis disAl disJuC bacFFF borRad50"
                  style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                  @click.stop="ruleForm.card_give_integral_type = 2"
                >
                  <div
                    v-if="ruleForm.card_give_integral_type === 2"
                    class="borRad50"
                    style="width: 6px;height: 6px;background: #41c3a8;"
                  />
                </div>
                <div class="mar-left5">使用该卡约课/签到时赠送积分</div>
              </div>
              <div
                v-if="ruleForm.card_give_integral_type === 2"
                class="dis disAl mar-top10"
                style="padding-left: 25px;"
              >
                <div class="dis disAl cuPo">
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                    @click.stop="ruleForm.card_give_integral_xuan = 1"
                  >
                    <div
                      v-if="ruleForm.card_give_integral_xuan === 1"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">每日赠送积分最多</div>
                  <el-form-item class="mp0" prop="card_give_integral_num">
                    <el-input
                      v-model="ruleForm.card_give_integral_num"
                      class="cen"
                      style="width: 80px;margin: 0px 10px"
                      size="small"
                      placeholder="次数"
                    />
                  </el-form-item>
                  <div>次</div>
                </div>
                <div class="dis disAl cuPo mar-left30">
                  <div
                    class="dis disAl disJuC bacFFF borRad50"
                    style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                    @click.stop="ruleForm.card_give_integral_xuan = 2,ruleForm.card_give_integral_num = null"
                  >
                    <div
                      v-if="ruleForm.card_give_integral_xuan === 2"
                      class="borRad50"
                      style="width: 6px;height: 6px;background: #41c3a8;"
                    />
                  </div>
                  <div class="mar-left5">不限制</div>
                </div>
              </div>
            </div>
          </div>
          <div class="forms_item2" style="width: 100%;padding: 20px">
            <div class="foSi14 dis disAl disJuB wid100">
              <div class="cuPo" @click="advanced_setting = !advanced_setting">
                <span class="mar-right5">高级设置</span>
                <i v-if="!advanced_setting" class="el-icon-arrow-down" />
                <i v-if="advanced_setting" class="el-icon-arrow-up" />
              </div>
              <div>(提示:高级设置可设置该卡的请假规则，开卡设置，预约限额等，建议设置)</div>
            </div>
            <div v-if="advanced_setting" class="wid90 mar mar-top20 foSi14" style="clear: both;">
              <div>卡相关设置</div>
              <div class="mar-top10" style="border: 1px dashed #ccc;padding: 20px;">
                <div class="dis disAl">
                  <div style="width: 30%">请假选项</div>
                  <div>
                    <div class="dis disAl">
                      <el-popover
                        placement="top-start"
                        title="提示"
                        width="400"
                        trigger="click"
                        content="选择不允许则不支持该会员卡请假，选择不限制则不限制会员卡请假天数/次数，选择允许需要填写，最大请假次数，累计可请假天数"
                      >
                        <i
                          slot="reference"
                          class="el-icon-question wenhao mar-right5"
                          style=""
                        />
                      </el-popover>
                      <div class="dis disAl cuPo">
                        <div
                          class="dis disAl disJuC bacFFF borRad50"
                          style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                          @click.stop="ruleForm.card_leaves = 2"
                        >
                          <div
                            v-if="ruleForm.card_leaves === 2"
                            class="borRad50"
                            style="width: 6px;height: 6px;background: #41c3a8;"
                          />
                        </div>
                        <div class="mar-left5">不允许</div>
                      </div>
                      <div class="dis disAl cuPo mar-left30">
                        <div
                          class="dis disAl disJuC bacFFF borRad50"
                          style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                          @click.stop="ruleForm.card_leaves = 1"
                        >
                          <div
                            v-if="ruleForm.card_leaves === 1"
                            class="borRad50"
                            style="width: 6px;height: 6px;background: #41c3a8;"
                          />
                        </div>
                        <div class="mar-left5">不限制</div>
                      </div>
                    </div>
                    <div class="dis disAl cuPo mar-left25">
                      <div
                        class="dis disAl disJuC bacFFF borRad50"
                        style="width: 14px;height: 14px;border: 1px solid #41c3a8;"
                        @click.stop="ruleForm.card_leaves = 3"
                      >
                        <div
                          v-if="ruleForm.card_leaves === 3"
                          class="borRad50"
                          style="width: 6px;height: 6px;background: #41c3a8;"
                        />
                      </div>
                      <div class="mar-left5">允许，有效期内可以请假</div>
                      <el-form-item class="mp0" prop="card_leaves_number">
                        <el-input
                          v-model="ruleForm.card_leaves_number"
                          class="cen"
                          style="width: 80px;margin: 0px 10px"
                          size="small"
                        />
                      </el-form-item>
                      <div>次，累计</div>
                      <el-form-item class="mp0" prop="card_leaves_day">
                        <el-input
                          v-model="ruleForm.card_leaves_day"
                          class="cen"
                          style="width: 80px;margin: 0px 10px"
                          size="small"
                        />
                      </el-form-item>
                      <div>天</div>
                    </div>
                  </div>
                </div>
                <div class="mar-top5 dis disAl">
                  <div style="width: 30%;">开卡设置：</div>
                  <div class="dis disAl">
                    <el-popover placement="top-start" title="提示" width="400" trigger="click" content="如不填写，则自动在发卡次日开卡。">
                      <i slot="reference" class="el-icon-question wenhao mar-right5" />
                    </el-popover>
                    <div class="dis disAl">
                      <div>发卡后</div>
                      <el-form-item class="mp0" prop="card_automatic">
                        <el-input v-model="ruleForm.card_automatic" class="cen" style="width: 100px;margin: 0px 10px" size="small" />
                      </el-form-item>
                      <div>天内未开卡自动开卡</div>
                    </div>
                  </div>
                </div>
                <div class="dis disAl">
                  <div style="width: 30%;">单节课可约人数上限：</div>
                  <el-popover placement="top-start" title="提示" width="400" trigger="click" content="指持有该会员卡的会员，每次预约该课程时可以带的朋友数量。根据预约人数，扣除该会员持有的会员卡次数或金额。">
                    <i slot="reference" class="el-icon-question wenhao mar-right5" />
                  </el-popover>
                  <el-form-item class="mp0" prop="card_one_class_make">
                    <el-input v-model="ruleForm.card_one_class_make" placeholder="默认单课可约1人" /></el-form-item>
                </div>
                <div class="mar-top5 dis disAl">
                  <div style="width: 30%;">每日可约次数上限：</div>
                  <div class="dis disAl">
                    <el-popover placement="top-start" title="提示" width="400" trigger="click" content="这张卡每天可约课的总次数。每天从00:00到23:59 计算一个循环。比如:设置为1，则表示该会员当天只能预约1次，当天预约1次后不能再约。">
                      <i slot="reference" class="el-icon-question wenhao mar-right5" style="margin-top: 8px" />
                    </el-popover>
                    <el-form-item class="mp0" prop="card_one_day_make">
                      <el-input v-model="ruleForm.card_one_day_make" style="width: 150px;margin: 0px 10px" size="small" placeholder="不限制预约次数" />
                    </el-form-item>
                  </div>
                </div>
                <div class="mar-top5 dis disAl">
                  <div style="width: 30%;">每周可约次数上限：</div>
                  <div class="dis disAl">
                    <el-popover placement="top-start" title="提示" width="400" trigger="click" content="这张卡每周可约课的总次数。每周从周一到周日计算一个循环。比如:设置为1，则表示该会员本周只能预约1次，本周预约1次后不能再约。">
                      <i slot="reference" class="el-icon-question wenhao mar-right5" style="margin-top: 8px" />
                    </el-popover>
                    <el-form-item class="mp0" prop="card_one_week_make">
                      <el-input v-model="ruleForm.card_one_week_make"style="width: 150px;margin: 0px 10px" size="small" placeholder="不限制预约次数" />
                    </el-form-item>
                  </div>
                </div>
                <div class="mar-top5 dis disAl">
                  <div style="width: 30%;">每月可约次数上限：</div>
                  <div class="dis disAl">
                    <el-popover placement="top-start" title="提示" width="400" trigger="click" content="这张卡每月可约课的总次数。每月从第一天到最后一天计算一个循环。比如:设置为1，则表示该会员本月只能预约1次，本月预约1次后不能再约。">
                      <i slot="reference" class="el-icon-question wenhao mar-right5" style="margin-top: 8px" />
                    </el-popover>
                    <el-form-item class="mp0" prop="card_one_month_make">
                      <el-input v-model="ruleForm.card_one_month_make" style="width: 150px;margin: 0px 10px" size="small" placeholder="不限制预约次数" />
                    </el-form-item>
                  </div>
                </div>
                <div class="mar-top5 dis disAl">
                  <div style="width: 30%;">可预约天数：</div>
                  <div class="dis disAl">
                    <el-popover placement="top-start" title="提示" width="400" trigger="click" content="可预约天数限制">
                      <i slot="reference" class="el-icon-question wenhao mar-right5" />
                    </el-popover>
                    <div class="dis disAl">
                      <div>会员最多可预约</div>
                      <el-form-item class="mp0" prop="card_appointment_days">
                        <el-input v-model="ruleForm.card_appointment_days" style="width: 100px;margin: 0px 10px" size="small" placeholder="不限制预约次数" />
                      </el-form-item>
                      <div>天的课程，0表示当天</div>
                    </div>
                  </div>
                </div>
                <div class="mar-top5 dis disAl">
                  <div style="width: 30%;">可用时间：</div>
                  <div class="dis disAl">
                    <el-popover placement="top-start" title="提示" width="400" trigger="click" content="可用时间内才可约">
                      <i slot="reference" class="el-icon-question wenhao mar-right5" />
                    </el-popover>
                    <div class="dis disAl cuPo">
                      <div class="dis disAl disJuC bacFFF borRad50" style="width: 14px;height: 14px;border: 1px solid #41c3a8;" @click.stop="ruleForm.card_available_time = 0">
                        <div v-if="ruleForm.card_available_time === 0" class="borRad50" style="width: 6px;height: 6px;background: #41c3a8;" />
                      </div>
                      <div class="mar-left5">全时段</div>
                    </div>
                    <div class="dis disAl cuPo mar-left30">
                      <div class="dis disAl disJuC bacFFF borRad50" style="width: 14px;height: 14px;border: 1px solid #41c3a8;" @click.stop="availableJson(1)">
                        <div v-if="ruleForm.card_available_time === 1" class="borRad50" style="width: 6px;height: 6px;background: #41c3a8;" />
                      </div>
                      <div class="mar-left5">自定义时段</div>
                    </div>
                  </div>
                </div>
                <div class="dis">
                  <div style="width: 30%;" />
                  <div>
                    <div v-if="ruleForm.card_available_time == 1" class="mar-top20 mar-left25">
                      <div>可用时间段内才可预约</div>
                      <div class="mar-top10">
                        <el-checkbox-group v-model="ruleForm.appointment_time" :min="1" @change="timeofappointment">
                          <el-checkbox v-for="(item,index) in weeklist" :key="index" class="mar-bott5" :label="item.id">{{ item.title }}</el-checkbox>
                        </el-checkbox-group>
                      </div>
                    </div>
                    <div v-show="ruleForm.card_available_time == 1" class="mar-top20" style="margin-left: 25px;">
                      <div>可用时段</div>
                      <div style="margin-top: 10px">
                        <div v-for="(item,index) in ruleForm.timelist" :key="index" class="dis disAl mar-top5">
                          <el-select v-model="item.k_shi" class="sel" style="width: 80px;" @change="availableJson(0)">
                            <el-option v-for="(item,index) in shiList" :key="index":label="item.label" :value="item.value" />
                          </el-select>
                          <div class="mar-left5 mar-right5">:</div>
                          <el-select
                            v-model="item.k_fen"
                            class="sel"
                            style="width: 80px;"
                            @change="availableJson(0)"
                          >
                            <el-option
                              v-for="(item,index) in fenList1"
                              :key="index"
                              :label="item.label"
                              :value="item.value"
                            />
                          </el-select>
                          <div class="mar-left10 mar-right10">至</div>
                          <el-select v-model="item.j_shi" class="sel" style="width: 80px;" @change="availableJson(0)">
                            <el-option v-for="(item,index) in shiList" :key="index" :label="item.label" :value="item.value" />
                          </el-select>
                          <div class="mar-left5 mar-right5">:</div>
                          <el-select
                            v-model="item.j_fen"
                            class="sel"
                            style="width: 80px;"
                            @change="availableJson(0)"
                          >
                            <el-option
                              v-for="(item,index) in fenList1"
                              :key="index"
                              :label="item.label"
                              :value="item.value"
                            />
                          </el-select>
                          <div
                            style="color: green;cursor: pointer"
                            class="mar-left10"
                            @click="deletetime(index)"
                          ><i
                            class="el-icon-delete"
                            style="font-size: 18px;margin-right: 3px"
                          />删除</div>
                        </div>
                      </div>
                      <div class="addtimelist" @click="ins_timelist">
                        <i class="el-icon-circle-plus-outline" style="font-size: 16px;" />
                        <div>新增可用时段</div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div v-if="advanced_setting" class="wid90 mar mar-top20" style="clear: both;">
            <div>用卡人相关设置</div>
            <div class="mar-top10" style="border: 1px dashed #ccc;padding: 20px;">
              <div class="mar-top5 dis disAl">
                <div style="width: 30%;">每日约课间隔时间限制：</div>
                <div>
                  <div class="dis disAl">
                    <el-popover placement="top-start" title="提示" width="400" trigger="click" content="支持设置xx分钟内不可连续约课，即用户预约某一节课程后，在这一节课程前后xx分钟内的其他课程不能预约">
                      <i slot="reference" class="el-icon-question wenhao mar-right5" />
                    </el-popover>
                    <el-form-item class="mp0" prop="card_lim_minute">
                      <el-input v-model="ruleForm.card_lim_minute" style="width: 100px;margin: 0px 10px" size="small" placeholder="不限制" />
                    </el-form-item>
                    <div>分钟内不可连续约课</div>
                  </div>
                </div>
              </div>
              <div class="mar-top5 dis disAl">
                <div style="width: 30%;">预约次数限制：</div>
                <div class="dis disAl">
                  <el-popover placement="top-start" title="提示" width="400" trigger="click" content="可限制会员最多只能提前预约xx次课程，避免会员提前预约n次课程但是不来上课">
                    <i slot="reference" class="el-icon-question wenhao mar-right5" />
                  </el-popover>
                  <div class="mar-left10">未结束课程预约次数限制为</div>
                  <el-form-item class="mp0" prop="card_make_number">
                    <el-input v-model="ruleForm.card_make_number" style="width: 100px;margin: 0px 10px" size="small" placeholder="0" />
                  </el-form-item>
                  <div>次，0表示不限制</div>
                </div>
              </div>
              <div class="mar-top5 dis disAl">
                <div style="width: 30%;">会员取消预约次数限制：</div>
                <div class="dis disAl">
                  <el-popover placement="top-start" title="提示" width="400" trigger="click" content="可限制会员最多取消预约的次数，避免会员过度失约，会员端取消次数受限后场馆支持操作取消">
                    <i slot="reference" class="el-icon-question wenhao mar-right5" style="margin-top: 8px" />
                  </el-popover>
                  <el-form-item class="mp0" prop="card_cancel_number">
                    <el-input
                      v-model="ruleForm.card_cancel_number"
                      style="width: 100px;margin: 0px 10px"
                      size="small"
                      placeholder="不限制"
                    />
                  </el-form-item>
                  <div class="mar-right5">次，每</div>
                  <el-select v-model="ruleForm.card_cancel_type" placeholder="请选择" size="small" style="width:87px">
                    <el-option v-for="item in cancellimit" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-form>
      <div class="buttom_btns">
        <div class="save">
          <el-button type="primary" class="bac6b7" @click.stop="submitForm('ruleForm')">保存</el-button>
        </div>
        <div class="nosave">
          <el-button type="info" @click="back">取消</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getXuan
} from '@/utils/limits.js'
import {
  mapGetters
} from 'vuex' // Secondary package based on el-pagination
import {
  schedCardAddEdit,
  details,
  course,
  getLevellist
} from '@/api/member'
import {
  uploadimg
} from '@/api/utils'

export default {
  name: 'ArticleList',
  components: {},
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    const cardCancel = (rule, value, callback) => {
      if (Number(value) === 0) {
        callback()
      } else if (value && !parseFloat(value) || value % 1 !== 0 || value < 0) {
        callback(new Error('请输入自然数'))
      } else {
        callback()
      }
    }
    const cardMake = (rule, value, callback) => {
      if (Number(value) === 0) {
        callback()
      } else if (value && !parseFloat(value) || value % 1 !== 0 || value < 0) {
        callback(new Error('请输入整数'))
      } else {
        callback()
      }
    }
    const cardLim = (rule, value, callback) => {
      if (value && (!parseFloat(value) || value % 1 !== 0) || value < 0) {
        callback(new Error('必须是正整数'))
      } else {
        callback()
      }
    }
    const cardAppointment = (rule, value, callback) => {
      if ((!parseFloat(value) || value === 0 || value % 1 !== 0) && value) {
        callback(new Error('请输入整数或不输入'))
      } else {
        callback()
      }
    }
    const cardMonth = (rule, value, callback) => {
      if ((!parseFloat(value) || value === 0 || value % 1 !== 0 || value < 1 || value > 1000) && value) {
        callback(new Error('请输入1~1000内正整数'))
      } else {
        callback()
      }
    }
    const cardDay = (rule, value, callback) => {
      if ((!parseFloat(value) || value === 0 || value % 1 !== 0 || value < 1 || value > 10) && value) {
        callback(new Error('请输入1~10内正整数'))
      } else {
        callback()
      }
    }
    const cardCass = (rule, value, callback) => {
      if (!parseFloat(value) || !value || value % 1 !== 0 || value < 1 || value > 10) {
        callback(new Error('请输入1~10内正整数'))
      } else {
        callback()
      }
    }
    const cardAutomatic = (rule, value, callback) => {
      if (!parseFloat(value) || !value || value % 1 !== 0 || value < 1 || value > 1000) {
        callback(new Error('请输入1~1000内正整数'))
      } else {
        callback()
      }
    }
    const cardLeaves1 = (rule, value, callback) => {
      if ((!parseFloat(value) || !value || value % 1 !== 0 || value < 1 || value > 1000) && this.ruleForm
        .card_leaves === 3) {
        callback(new Error('请输入1~1000内正整数'))
      } else {
        callback()
      }
    }
    const cardLeaves = (rule, value, callback) => {
      if ((!parseFloat(value) || !value || value % 1 !== 0 || value < 1 || value > 100) && this.ruleForm
        .card_leaves === 3) {
        callback(new Error('请输入1~100内正整数'))
      } else {
        callback()
      }
    }
    const cardGiveNum = (rule, value, callback) => {
      if (this.ruleForm.card_give_integral_xuan === 1 && this.ruleForm.card_give_integral_type === 2 && this
        .ruleForm.card_type === 1 && value) {
        if (!parseFloat(value) || value % 1 !== 0 || value < 1 || value > 100) {
          callback(new Error('请输入1~100之间的正整数或留空'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    const cardGive = (rule, value, callback) => {
      if ((!parseFloat(value) || value % 1 !== 0 || value < 1 || value > 10000000) && value) {
        callback(new Error('请输入1~10000000之间的正整数或留空'))
      } else {
        callback()
      }
    }
    const cardMoney = (rule, value, callback) => {
      if ((!parseFloat(value) || !value || value % 1 !== 0 || value < 1 || value > 100000) && this.ruleForm
        .card_type !== 1) {
        callback(new Error('请输入1~100000内整数值'))
      } else {
        callback()
      }
    }
    const cardPeriod = (rule, value, callback) => {
      if (!parseFloat(value) || !value || value % 1 !== 0 || value < 1 || value > 3650) {
        callback(new Error('请输入1~3650内正整数'))
      } else {
        callback()
      }
    }
    const sellPrice1 = (rule, value, callback) => {
      var len = 0
      if (!value) {
        callback()
      } else {
        if (value) {
          var tem = value.toString().split('.')
          len = tem.length >= 2 ? tem[1].length : 0
        }
        if (!parseFloat(value) || len > 2 || value < 0 || value > 10000000) {
          callback(new Error('请输入0~10000000数值（最小单位到分）'))
        } else {
          callback()
        }
      }
    }
    const sellPrice = (rule, value, callback) => {
      var len = 0
      if (value) {
        var tem = value.toString().split('.')
        len = tem.length >= 2 ? tem[1].length : 0
      }
      if (!parseFloat(value) || !value || len > 2 || value < 0.01 || value > 10000000) {
        callback(new Error('请输入0.01~10000000数值（最小单位到分）'))
      } else {
        callback()
      }
    }
    const validateValue = (rule, value, callback) => {
      var pd = false
      this.ruleForm.card_applicable.forEach(item => {
        if (item.id === rule.field) {
          pd = true
        }
      })
      if (pd) {
        for (var i = 0; i < this.treeList.children.length; i++) {
          for (var j = 0; j < this.treeList.children[i].children.length; j++) {
            if (this.treeList.children[i].children[j].course_id === rule.field) {
              value = this.treeList.children[i].children[j].frequency
            }
          }
          if (!parseFloat(value) || !value || value % 1 !== 0) {
            callback(new Error('请输入正数'))
          } else {
            callback()
          }
        }
      } else {
        callback()
      }
    }
    const validateValue1 = (rule, value, callback) => {
      var pd = false
      this.ruleForm.card_applicable.forEach(item => {
        if (item.id === rule.field) {
          pd = true
        }
      })
      if (pd) {
        for (var i = 0; i < this.treeList.children.length; i++) {
          for (var j = 0; j < this.treeList.children[i].children.length; j++) {
            if (this.treeList.children[i].children[j].course_id === rule.field) {
              value = this.treeList.children[i].children[j].frequency
            }
          }
        }
        var len = 0
        if (value) {
          console.log(value.toString().split('.'))
          len = value.toString().split('.').length > 1 ? value.toString().split('.')[1].length : 0
        }
        if (!parseFloat(value) || !value || len > 1) {
          callback(new Error('请输入次数(最多一位小数)'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      shiList: [],
      fenList: [],
      fenList1: [],
      advanced_setting: false, // 高级设置开关
      data: [{
        id: 1,
        label: '一级 1',
        children: [{
          id: 4,
          label: '二级 1-1',
          children: [{
            id: 9,
            label: '三级 1-1-1'
          }, {
            id: 10,
            label: '三级 1-1-2'
          }]
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      type: 0,
      list: null,
      total: 0,
      listLoading: false,
      search: {
        membership: []
      },
      ruleForm: {
        stock: 9999,
        name: null,
        card_type: 1,
        sell_price: 0,
        card_available_time: 0,
        appointment_time: [1],
        timelist: [{
          k_shi: 0,
          k_fen: 0,
          j_shi: 0,
          j_fen: 0
        }],
        card_available_json: null,
        card_cancel_type: 1,
        trId: null,
        card_applicable: null,
        market_price: 0,
        pic: 'https://www.jianyigongxiang.com/public/membercard/sck.jpg',
        picUp: false,
        pics: [],
        card_period_type: 2,
        card_period: null,
        card_money: null,
        card_give_integral: null,
        card_leaves: 1,
        card_leaves_number: null,
        card_leaves_day: null,
        card_automatic: 730,
        card_one_class_make: 1,
        card_one_day_make: null,
        card_one_week_make: null,
        card_one_month_make: null,
        card_appointment_days: null,
        card_give_integral_type: 2,
        card_give_integral_xuan: 2,
        card_give_integral_num: null,
        card_lim_minute: null,
        card_make_number: 0,
        card_cancel_number: null,
        sellpoint: null,
        commissionset: -1,
        fenhongset: 0,
        teamfenhongset: -1,
        gdfenhongset: -1,
        areafenhongset: -1,
        scoredkmaxset: -1,
        scoredkmaxval: null,
        status: 0,
        cost_price: 0
      },
      rules: {
        card_cancel_number: [{
          required: true,
          trigger: 'blur',
          validator: cardCancel
        }],
        card_make_number: [{
          required: true,
          trigger: 'blur',
          validator: cardMake
        }],
        card_lim_minute: [{
          required: true,
          trigger: 'blur',
          validator: cardLim
        }],
        card_give_integral_num: [{
          required: true,
          trigger: 'blur',
          validator: cardGiveNum
        }],
        card_appointment_days: [{
          required: true,
          trigger: 'blur',
          validator: cardAppointment
        }],
        card_one_week_make: [{
          required: true,
          trigger: 'blur',
          validator: cardMonth
        }],
        card_one_month_make: [{
          required: true,
          trigger: 'blur',
          validator: cardMonth
        }],
        card_one_day_make: [{
          required: true,
          trigger: 'blur',
          validator: cardDay
        }],
        card_one_class_make: [{
          required: true,
          trigger: 'blur',
          validator: cardCass
        }],
        card_automatic: [{
          required: true,
          trigger: 'blur',
          validator: cardAutomatic
        }],
        card_leaves_day: [{
          required: true,
          trigger: 'blur',
          validator: cardLeaves1
        }],
        card_leaves_number: [{
          required: true,
          trigger: 'blur',
          validator: cardLeaves
        }],
        card_give_integral: [{
          required: true,
          trigger: 'blur',
          validator: cardGive
        }],
        card_money: [{
          required: true,
          trigger: 'blur',
          validator: cardMoney
        }],
        card_period: [{
          required: true,
          trigger: 'blur',
          validator: cardPeriod
        }],
        cost_price: [{
          required: true,
          trigger: 'blur',
          validator: sellPrice1
        }],
        market_price: [{
          required: true,
          trigger: 'blur',
          validator: sellPrice
        }],
        sell_price: [{
          required: true,
          trigger: 'blur',
          validator: sellPrice
        }],
        name: [{
          required: true,
          message: '请输入1~20个字的体验卡种类',
          trigger: 'blur'
        }],
        value: [{
          required: true,
          trigger: 'blur',
          validator: validateValue1
        }],
        value1: [{
          required: true,
          trigger: 'blur',
          validator: validateValue
        }]
      },
      options: [],
      listQuery: {
        page: 1,
        limit: 20
      },
      // 防止重复提交
      loading: false,
      // 裁剪过后的图片
      imgUrl: '',
      cardtypelist: [],
      fenhongsetList: [{
        label: '按会员等级',
        value: 0
      }, {
        label: '单独设置分红比例',
        value: 1
      }, {
        label: '单独设置分红金额',
        value: 2
      }, {
        label: '不参与分红',
        value: -1
      }],
      scoredkmaxList: [{
        label: '按照系统设置抵扣',
        value: 0
      }, {
        label: '单独设置抵扣比例',
        value: 1
      }, {
        label: '单独设置抵扣金额',
        value: 2
      }, {
        label: '不可用积分抵扣',
        value: -1
      }],
      commissionsetList: [{
        label: '按会员等级',
        value: 0
      }, {
        label: '价格比例 ',
        value: 1
      }, {
        label: '固定金额',
        value: 2
      }, {
        label: '分销送积分',
        value: 3
      }, {
        label: '比例加积分',
        value: 5
      }, {
        label: '提成金额加积分',
        value: 6
      }, {
        label: '不参与分销',
        value: -1
      }],
      statusList: [{
        label: '上架',
        value: 1
      }, {
        label: '下架',
        value: 0
      }],
      timetypelist: [{
        label: '月',
        value: 2
      }, {
        label: '天',
        value: 1
      }],
      priceTypeList: [{
        label: '询价',
        value: 1
      }, {
        label: '默认',
        value: 0
      }],
      // 会员取消预约次数限制
      cancellimit: [{
        label: '日',
        value: 1
      }, {
        label: '周',
        value: 2
      }, {
        label: '月',
        value: 3
      }],
      weeklist: [{
        title: '周一',
        id: 1,
        is_support: true
      }, {
        title: '周二',
        id: 2,
        is_support: false
      }, {
        title: '周三',
        id: 3,
        is_support: false
      }, {
        title: '周四',
        id: 4,
        is_support: false
      }, {
        title: '周五',
        id: 5,
        is_support: false
      }, {
        title: '周六',
        id: 6,
        is_support: false
      }, {
        title: '周日',
        id: 7,
        is_support: false
      }],
      treeList: [],
      teamfenhonglv: false,
      fenhong: false,
      areafenhongbl: false,
      td_type: true,
      id: null,
      levellist: null
    }
  },
  computed: {
    ...mapGetters([
      'permission_routes',
      'roles'
    ])
  },
  created() {
    console.log(new Date(2016, 9, 10, 8, 40))
    var query = this.$route.query
    var str_head = ''
    this.type = query.type
    if (query.type === '1') {
      // 体验卡
      str_head = '新增体验卡种类'
      this.cardtypelist = [{
        label: '期限卡',
        value: 1
      }, {
        label: '次数卡',
        value: 2
      }, {
        label: '储值卡',
        value: 3
      }]
      this.ruleForm.commissionset = -1
      this.ruleForm.fenhongset = 0
      this.ruleForm.scoredkmaxset = -1
    } else {
      str_head = '新增会员卡种类'
      this.cardtypelist = [{
        label: '期限卡',
        value: 1
      }, {
        label: '次数卡',
        value: 2
      },
      {
        label: '储值卡',
        value: 3
      }
      ]
    }
    console.log(str_head)
    for (var i = 0; i < 24; i++) {
      this.shiList.push({
        label: i < 10 ? '0' + i : i,
        value: i
      })
    }
    for (var i = 0; i < 60; i++) {
      this.fenList1.push({
        label: i < 10 ? '0' + i : i,
        value: i
      })
    }
    for (var i = 0; i < 60; i += 5) {
      this.fenList.push({
        label: i < 10 ? '0' + i : i,
        value: i
      })
    }
    var xuanList = [{
      name: str_head,
      url: '/member/editmembercardname?type=' + this.type + (this.id ? '&id=' + this.id : ''),
      pd: true
    }]
    var xuanList1 = getXuan(xuanList, this.roles)
    this.$store.dispatch('user/changeXuan', {
      key: 'xuanList',
      value: xuanList1
    })
    this.$store.dispatch('user/changeXuan', {
      key: 'xuan',
      value: 0
    })
    this.id = query.id
    this.getLevellist()
  },
  methods: {
    getLevellist() {
      getLevellist().then(response => {
        const {
          data
        } = response
        for (var i = 0; i < data.length; i++) {
          if (data[i].teamfenhonglv > 0) {
            this.teamfenhonglv = true
          }
          if (data[i].fenhong > 0) {
            this.fenhong = true
          }
          if (data[i].areafenhongbl > 0) {
            this.areafenhongbl = true
          }
          data[i].b_one = 'b_one' + data[i].id
          data[i].b_two = 'b_two' + data[i].id
          data[i].b_three = 'b_three' + data[i].id
          data[i].one_money = 'one_money' + data[i].id
          data[i].two_money = 'two_money' + data[i].id
          data[i].three_money = 'three_money' + data[i].id
          data[i].j_one = 'j_one' + data[i].id
          data[i].j_two = 'j_two' + data[i].id
          data[i].j_three = 'j_three' + data[i].id
          data[i].teamfenhongset1 = 'teamfenhongset1' + data[i].id
          data[i].teamfenhongset2 = 'teamfenhongset2' + data[i].id
          data[i].gdfenhongset1 = 'gdfenhongset1' + data[i].id
          data[i].gdfenhongset2 = 'gdfenhongset2' + data[i].id
          data[i].areafenhongset1 = 'areafenhongset1' + data[i].id
          data[i].areafenhongset2 = 'areafenhongset2' + data[i].id
          this.ruleForm['b_one' + data[i].id] = ''
          this.ruleForm['b_two' + data[i].id] = ''
          this.ruleForm['b_three' + data[i].id] = ''
          this.ruleForm['one_money' + data[i].id] = ''
          this.ruleForm['two_money' + data[i].id] = ''
          this.ruleForm['three_money' + data[i].id] = ''
          this.ruleForm['j_one' + data[i].id] = ''
          this.ruleForm['j_two' + data[i].id] = ''
          this.ruleForm['j_three' + data[i].id] = ''
          this.ruleForm['teamfenhongset1' + data[i].id] = ''
          this.ruleForm['teamfenhongset2' + data[i].id] = ''
          this.ruleForm['gdfenhongset1' + data[i].id] = ''
          this.ruleForm['gdfenhongset2' + data[i].id] = ''
          this.ruleForm['areafenhongset1' + data[i].id] = ''
          this.ruleForm['areafenhongset2' + data[i].id] = ''
        }
        this.levellist = data
        if (this.id) {
          this.getList()
        } else {
          this.getTree()
        }
      })
    },
    ruleFormChange(e) {
      this.$forceUpdate()
    },
    cardTypeChange() {
      console.log('123', this.ruleForm.card_type)
      if (this.ruleForm.card_type === 1 && !this.ruleForm.picUp) {
        this.ruleForm.pic = 'https://www.jianyigongxiang.com/public/membercard/sck.jpg'
      } else if (this.ruleForm.card_type === 2 && !this.ruleForm.picUp) {
        this.ruleForm.pic = 'https://www.jianyigongxiang.com/public/membercard/csk.jpg'
      } else if (this.ruleForm.card_type === 3 && !this.ruleForm.picUp) {
        this.ruleForm.pic = 'https://www.jianyigongxiang.com/public/membercard/card-type-3.png'
      }
      // else if(this.ruleForm.card_type === 3){
      // 	this.ruleForm.pic = 'https://www.jianyigongxiang.com/public/membercard/qxk.jpg'
      // }
    },
    getList() {
      var date = {
        id: this.id
      }
      details(date).then(response => {
        const {
          data
        } = response
        this.ruleForm.name = data.name
        this.ruleForm.stock = data.stock
        this.ruleForm.sell_price = data.sell_price
        this.ruleForm.card_type = data.card_type
        this.ruleForm.card_available_time = data.card_available_time
        this.ruleForm.card_available_json = data.card_available_json
        this.ruleForm.trId = data.card_applicable_brand
        if (data.card_available_json) {
          console.log(data.card_available_json)
          var json = JSON.parse(data.card_available_json)
          console.log(json)
          this.ruleForm.appointment_time = json.week
          var ass = []
          console.log(json)
          json.timelist.forEach(item => {
            var start = item.start_time.split(':')
            var end = item.end_time.split(':')
            ass.push({
              k_shi: Number(start[0]),
              k_fen: Number(start[1]),
              j_shi: Number(end[0]),
              j_fen: Number(end[1])
            })
          })
          this.ruleForm.timelist = ass.length === 0 ? [{
            k_shi: 0,
            k_fen: 0,
            j_shi: 0,
            j_fen: 0
          }] : ass
        }
        this.ruleForm.card_cancel_type = data.card_cancel_type
        if (data.card_applicable) {
          this.ruleForm.card_applicable = data.card_applicable

          console.log('快快快快快快快快快快')
          console.log(this.ruleForm.card_applicable)
        }
        this.ruleForm.market_price = data.market_price
        this.ruleForm.pic = data.pic
        this.ruleForm.picUp = true
        if (data.pics) {
          this.ruleForm.pics = data.pics.split(',')
        }
        this.ruleForm.card_period_type = data.card_period_type
        this.ruleForm.card_period = data.card_period
        this.ruleForm.card_money = data.card_money
        this.ruleForm.card_give_integral = data.card_give_integral
        this.ruleForm.card_leaves = data.card_leaves
        this.ruleForm.card_leaves_number = data.card_leaves_number
        this.ruleForm.card_leaves_day = data.card_leaves_day
        this.ruleForm.card_automatic = data.card_automatic
        this.ruleForm.card_one_class_make = data.card_one_class_make
        this.ruleForm.card_one_day_make = data.card_one_day_make
        this.ruleForm.card_one_week_make = data.card_one_week_make
        this.ruleForm.card_one_month_make = data.card_one_month_make
        this.ruleForm.card_appointment_days = data.card_appointment_days
        this.ruleForm.card_give_integral_type = data.card_give_integral_type
        this.ruleForm.card_give_integral_xuan = !data.card_give_integral_num ? 2 : 1
        this.ruleForm.card_give_integral_num = data.card_give_integral_num
        this.ruleForm.card_lim_minute = data.card_lim_minute
        this.ruleForm.card_make_number = data.card_make_number
        this.ruleForm.card_cancel_number = data.card_cancel_number
        this.ruleForm.sellpoint = data.sellpoint
        this.ruleForm.commissionset = data.commissionset
        this.ruleForm.fenhongset = data.fenhongset
        this.ruleForm.teamfenhongset = data.teamfenhongset
        this.ruleForm.gdfenhongset = data.gdfenhongset
        this.ruleForm.areafenhongset = data.areafenhongset
        this.ruleForm.scoredkmaxset = data.scoredkmaxset
        this.ruleForm.scoredkmaxval = data.scoredkmaxval
        this.ruleForm.cost_price = data.cost_price
        this.ruleForm.status = data.status
        for (var i = 0; i < this.levellist.length; i++) {
          // console.log('等级id：',this.levellist[i].id);
          if (data.commissiondata1[this.levellist[i].id]) {
            this.ruleForm['b_one' + this.levellist[i].id] = data.commissiondata1[this.levellist[i].id]
              .commission1
            this.ruleForm['b_two' + this.levellist[i].id] = data.commissiondata1[this.levellist[i].id]
              .commission2
            this.ruleForm['b_three' + this.levellist[i].id] = data.commissiondata1[this.levellist[i]
              .id].commission3
          }

          if (data.commissiondata2[this.levellist[i].id]) {
            this.ruleForm['one_money' + this.levellist[i].id] = data.commissiondata2[this.levellist[i]
              .id].commission1
            this.ruleForm['two_money' + this.levellist[i].id] = data.commissiondata2[this.levellist[i]
              .id].commission2
            this.ruleForm['three_money' + this.levellist[i].id] = data.commissiondata2[this.levellist[
              i].id].commission3
          }

          if (data.commissiondata3[this.levellist[i].id]) {
            this.ruleForm['j_one' + this.levellist[i].id] = data.commissiondata3[this.levellist[i].id]
              .commission1
            this.ruleForm['j_two' + this.levellist[i].id] = data.commissiondata3[this.levellist[i].id]
              .commission2
            this.ruleForm['j_three' + this.levellist[i].id] = data.commissiondata3[this.levellist[i]
              .id].commission3
          }

          if (data.teamfenhongdata1[this.levellist[i].id]) {
            this.ruleForm['teamfenhongset1' + this.levellist[i].id] = data.teamfenhongdata1[this
              .levellist[i].id].commission
          }
          if (data.teamfenhongdata2[this.levellist[i].id]) {
            this.ruleForm['teamfenhongset2' + this.levellist[i].id] = data.teamfenhongdata2[this
              .levellist[i].id].commission
          }
          if (data.gdfenhongdata1[this.levellist[i].id]) {
            this.ruleForm['gdfenhongset1' + this.levellist[i].id] = data.gdfenhongdata1[this.levellist[
              i].id].commission
          }
          if (data.gdfenhongdata2[this.levellist[i].id]) {
            this.ruleForm['gdfenhongset2' + this.levellist[i].id] = data.gdfenhongdata2[this.levellist[
              i].id].commission
          }
          if (data.areafenhongdata1[this.levellist[i].id]) {
            this.ruleForm['areafenhongset1' + this.levellist[i].id] = data.areafenhongdata1[this
              .levellist[i].id].commission
          }
          if (data.areafenhongdata2[this.levellist[i].id]) {
            this.ruleForm['areafenhongset2' + this.levellist[i].id] = data.areafenhongdata2[this
              .levellist[i].id].commission
          }
        }
        this.getTree(1)
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var pics = ''
          this.ruleForm.pics.forEach(item => {
            pics === '' ? pics = item : pics += ',' + item
          })
          var commissiondata1 = {}
          var commissiondata2 = {}
          var commissiondata3 = {}
          var gdfenhongdata1 = {}
          var gdfenhongdata2 = {}
          var teamfenhongdata1 = {}
          var teamfenhongdata2 = {}
          var areafenhongdata1 = {}
          var areafenhongdata2 = {}
          for (var i = 0; i < this.levellist.length; i++) {
            commissiondata1[this.levellist[i].id] = {
              'commission1': this.ruleForm['b_one' + this.levellist[i].id] | 0,
              'commission2': this.ruleForm['b_two' + this.levellist[i].id] | 0,
              'commission3': this.ruleForm['b_three' + this.levellist[i].id] | 0
            }
            commissiondata2[this.levellist[i].id] = {
              'commission1': this.ruleForm['one_money' + this.levellist[i].id] | 0,
              'commission2': this.ruleForm['two_money' + this.levellist[i].id] | 0,
              'commission3': this.ruleForm['three_money' + this.levellist[i].id] | 0
            }
            commissiondata3[this.levellist[i].id] = {
              'commission1': this.ruleForm['j_one' + this.levellist[i].id] | 0,
              'commission2': this.ruleForm['j_two' + this.levellist[i].id] | 0,
              'commission3': this.ruleForm['j_three' + this.levellist[i].id] | 0
            }
            teamfenhongdata1[this.levellist[i].id] = {
              'commission': this.ruleForm['teamfenhongset1' + this.levellist[i].id] | 0
            }
            teamfenhongdata2[this.levellist[i].id] = {
              'commission': this.ruleForm['teamfenhongset2' + this.levellist[i].id] | 0
            }
            gdfenhongdata1[this.levellist[i].id] = {
              'commission': this.ruleForm['gdfenhongset1' + this.levellist[i].id] | 0
            }
            gdfenhongdata2[this.levellist[i].id] = {
              'commission': this.ruleForm['gdfenhongset2' + this.levellist[i].id] | 0
            }

            areafenhongdata1[this.levellist[i].id] = {
              'commission': this.ruleForm['areafenhongset1' + this.levellist[i].id] | 0
            }
            areafenhongdata2[this.levellist[i].id] = {
              'commission': this.ruleForm['areafenhongset2' + this.levellist[i].id] | 0
            }
          }
          var guigedata = [{
            'k': 0,
            'title': this.ruleForm.name,
            'items': [{
              'k': 0,
              'title': this.ruleForm.name
            }]
          }]
          if ((this.ruleForm.scoredkmaxset === 1 || this.ruleForm.scoredkmaxset === 2) && !this
            .ruleForm.scoredkmaxval) {
            this.$message.error('请填写最多抵扣金额')
            return false
          }
          var data = {
            name: this.ruleForm.name,
            stock: this.ruleForm.stock,
            card_type: this.ruleForm.card_type,
            market_price: this.ruleForm.market_price,
            sell_price: this.ruleForm.sell_price,
            card_money: this.ruleForm.card_money,
            card_period: this.ruleForm.card_period,
            card_period_type: this.ruleForm.card_period_type,
            card_applicable_brand: this.ruleForm.trId,
            card_applicable: JSON.stringify(this.ruleForm.card_applicable),
            card_give_integral: this.ruleForm.card_give_integral,
            card_leaves: this.ruleForm.card_leaves,
            card_leaves_number: this.ruleForm.card_leaves_number,
            card_leaves_day: this.ruleForm.card_leaves_day,
            card_automatic: this.ruleForm.card_automatic,
            card_one_class_make: this.ruleForm.card_one_class_make,
            card_one_day_make: this.ruleForm.card_one_day_make,
            card_one_week_make: this.ruleForm.card_one_week_make,
            card_one_month_make: this.ruleForm.card_one_month_make,
            card_appointment_days: this.ruleForm.card_appointment_days,
            card_available_time: this.ruleForm.card_available_time,
            card_available_json: this.ruleForm.card_available_json,
            card_lim_minute: this.ruleForm.card_lim_minute,
            card_make_number: this.ruleForm.card_make_number,
            card_cancel_number: this.ruleForm.card_cancel_number,
            card_cancel_type: this.ruleForm.card_cancel_type,
            card_state: 0,
            card_is_experience: this.type === '1' ? 1 : 0,
            pic: this.ruleForm.pic,
            pics: pics,
            sellpoint: this.ruleForm.sellpoint,
            price_type: 0,
            commissionset: this.ruleForm.commissionset,
            commissiondata1: JSON.stringify(commissiondata1),
            commissiondata2: JSON.stringify(commissiondata2),
            commissiondata3: JSON.stringify(commissiondata3),
            fenhongset: this.ruleForm.fenhongset,
            gdfenhongset: this.ruleForm.gdfenhongset,
            gdfenhongdata1: JSON.stringify(gdfenhongdata1),
            gdfenhongdata2: JSON.stringify(gdfenhongdata2),
            teamfenhongset: this.ruleForm.teamfenhongset,
            teamfenhongdata1: JSON.stringify(teamfenhongdata1),
            teamfenhongdata2: JSON.stringify(teamfenhongdata2),
            areafenhongset: this.ruleForm.areafenhongset,
            areafenhongdata1: JSON.stringify(areafenhongdata1),
            areafenhongdata2: JSON.stringify(areafenhongdata2),
            guigedata: JSON.stringify(guigedata),
            freighttype: 1,
            scoredkmaxset: this.ruleForm.scoredkmaxset,
            scoredkmaxval: this.ruleForm.scoredkmaxval,
            status: this.ruleForm.status,
            cost_price: this.ruleForm.cost_price,
            print_name: this.ruleForm.name,
            id: this.id,
            card_give_integral_type: this.ruleForm.card_give_integral_type,
            card_give_integral_num: this.ruleForm.card_give_integral_num
          }
          schedCardAddEdit(data).then(response => {
            this.back()
          }).catch(error => {
            console.log(error)
          })
        } else {
          this.$message.error('请按规则填写完整信息')
          return false
        }
      })
    },
    deletetime(index) {
      if (this.ruleForm.timelist.length === 1) {
        return this.$message({
          message: '需至少保留一项设置',
          type: 'warning'
        })
      }
      this.ruleForm.timelist.splice(index, 1)
      this.availableJson(0)
    },
    ins_timelist() {
      var arr = {
        k_shi: 0,
        k_fen: 0,
        j_shi: 0,
        j_fen: 0
      }
      // if (this.ruleForm.timelist.length >= 3) {
      //   return this.$message({
      //     message: '最多添加三个时间段',
      //     type: 'warning'
      //   })
      // }
      this.ruleForm.timelist.push(arr)
      this.availableJson(0)
    },
    timeofappointment(e) {
      this.ruleForm.appointment_time = e
      this.availableJson(0)
    },
    availableJson(index) {
      if (index === 1) {
        this.ruleForm.card_available_time = 1
      }
      var ass = []
      for (var i = 0; i < this.ruleForm.timelist.length; i++) {
        ass.push({
          start_time: this.shiList[this.ruleForm.timelist[i].k_shi].label + ':' + this.fenList1[this
            .ruleForm.timelist[i].k_fen].label,
          end_time: this.shiList[this.ruleForm.timelist[i].j_shi].label + ':' + this.fenList1[this
            .ruleForm.timelist[i].j_fen].label
        })
      }
      var json = {
        week: this.ruleForm.appointment_time,
        timelist: ass
      }
      this.ruleForm.card_available_json = JSON.stringify(json)
    },
    back() {
      this.$router.go(-1)
    },
    getTree(ind) {
      const date = {
        card_id: this.id
      }
      course(date).then(response => {
        const {
          data
        } = response
        var treeList = []
        for (var l = 0; l < data.length; l++) {
          var row = []
          var bas = 0
          for (var j = 0; j < data[l].courses.length; j++) {
            var a = 0
            if (data[l].courses[j].is_support === 1) {
              bas = 1
            }
            for (var i = 0; i < row.length; i++) {
              if (row[i].course_type === data[l].courses[j].course_type) {
                row[i].children.push({
                  course_id: data[l].courses[j].course_id,
                  coach_name: data[l].courses[j].coach_name,
                  name: data[l].courses[j].course_name,
                  is_support: data[l].courses[j].is_support === 1,
                  frequency: data[l].courses[j].charge,
                  tr: true
                })
                a = 1
              }
            }
            if (a === 0) {
              row.push({
                course_type: data[l].courses[j].course_type,
                name: data[l].courses[j].course_type_name,
                is_support: true,
                tr: true,
                children: [{
                  course_id: data[l].courses[j].course_id,
                  coach_name: data[l].courses[j].coach_name,
                  name: data[l].courses[j].course_name,
                  is_support: data[l].courses[j].is_support === 1,
                  frequency: data[l].courses[j].charge,
                  tr: true
                }]
              })
            }
          }
          for (var i = 0; i < row.length; i++) {
            var a = 0
            console.log(row[i].children.length)
            for (var j = 0; j < row[i].children.length; j++) {
              console.log(row[i].children[j])
              if (row[i].children[j].is_support) {
                a = 1
              }
            }
            console.log(a)
            if (a === 0) {
              row[i].is_support = false
            } else {
              row[i].is_support = true
            }
          }
          treeList.push({
            venue_id: data[l].value_id,
            name: data[l].value_name,
            is_support: row.length > 0 ? bas === 1 : data[l].is_support === 1,
            tr: true,
            children: row
          })
        }
        this.treeList = treeList
        console.log('看看tree')
        console.log(this.treeList)
        this.getTreeId()
      })
    },
    treeChange(index2, index, index1, biaoshi) {
      var is_support
      if (biaoshi === 0) {
        is_support = this.treeList[index2].is_support
        for (var i = 0; i < this.treeList[index2].children.length; i++) {
          this.treeList[index2].children[i].is_support = is_support
          for (var j = 0; j < this.treeList[index2].children[i].children.length; j++) {
            this.treeList[index2].children[i].children[j].is_support = is_support
          }
        }
      } else if (biaoshi === 1) {
        is_support = this.treeList[index2].children[index].is_support
        for (var j = 0; j < this.treeList[index2].children[index].children.length; j++) {
          this.treeList[index2].children[index].children[j].is_support = is_support
        }
        if (!is_support) {
          var a = 0
          for (var i = 0; i < this.treeList[index2].children.length; i++) {
            if (this.treeList[index2].children[i].is_support) {
              a = 1
            }
          }
          if (a === 0) {
            this.treeList[index2].is_support = false
          }
        } else {
          this.treeList[index2].is_support = true
        }
      } else if (biaoshi === 2) {
        is_support = this.treeList[index2].children[index].children[index1].is_support
        if (!is_support) {
          var a = 0
          for (var j = 0; j < this.treeList[index2].children[index].children.length; j++) {
            if (this.treeList[index2].children[index].children[j].is_support) {
              a = 1
            }
          }
          if (a === 0) {
            this.treeList[index2].children[index].is_support = false
            var b = 0
            for (var i = 0; i < this.treeList[index2].children.length; i++) {
              if (this.treeList[index2].children[i].is_support) {
                b = 1
              }
            }
            if (b === 0) {
              this.treeList[index2].is_support = false
            }
          } else {
            this.treeList[index2].is_support = true
            this.treeList[index2].children[index].is_support = true
          }
        } else {
          this.treeList[index2].is_support = true
          this.treeList[index2].children[index].is_support = true
        }
      }
      this.getTreeId()
    },
    cardAppChange(index2, index, index1) {
      if (this.treeList[index2].children[index].children[index1].is_support) {
        for (var j = 0; j < this.ruleForm.card_applicable.length; j++) {
          if (this.ruleForm.card_applicable[j].id === this.treeList[index2].children[index].children[index1]
            .course_id) {
            this.ruleForm.card_applicable[j].frequency = this.treeList[index2].children[index].children[
              index1].frequency
          }
        }
      }
      console.log('256156161', this.ruleForm.card_applicable)
    },
    getTreeId() {
      var row = []
      var rews = ''
      for (var l = 0; l < this.treeList.length; l++) {
        if (this.treeList[l].is_support) {
          rews === '' ? rews = this.treeList[l].venue_id : rews += ',' + this.treeList[l].venue_id
          for (var i = 0; i < this.treeList[l].children.length; i++) {
            for (var j = 0; j < this.treeList[l].children[i].children.length; j++) {
              console.log(this.treeList[l].children[i].children[j])
              row.push({
                id: this.treeList[l].children[i].children[j].course_id,
                frequency: this.treeList[l].children[i].children[j].frequency,
                pd: this.treeList[l].children[i].children[j].is_support
              })
            }
          }
        }
      }
      console.log('123131', row)
      this.ruleForm.trId = rews
      this.ruleForm.card_applicable = row
      console.log(this.ruleForm.trId)
      console.log(this.ruleForm.card_applicable)
    },
    handleAvatarSuccess(file) {
      const mf = new FormData()
      mf.append('file', file.file)
      uploadimg(mf).then(response => {
        const {
          data
        } = response
        this.ruleForm.pic = data
        this.ruleForm.picUp = true
      })
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 5
      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG或PNG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 5MB!')
      }
      return isJPG && isLt2M
    },
    handleAvatarSuccess1(fileList) {
      const mf = new FormData()
      mf.append('file', fileList.file)
      uploadimg(mf).then(response => {
        const {
          data
        } = response
        this.ruleForm.pics = this.ruleForm.pics.concat(data)
      })
    },
    deletePics(index) {
      this.ruleForm.pics.splice(index, 1)
    }
  }
}
</script>

<style scoped>
.yh_content {
  padding: 20px;
}

.contents {
  width: 860px;
  /* border: 1px solid red; */
  margin: 0px auto;
  padding:  10px
}

.yh_topsearch {
  border: 1px  solid #ccc;
  padding: 20rpx;

}

.yh_dis {
  display:  flex;
}

.yh_disAlc {
  align-items: center;
}

.touxiang  {
  width: 70px;
  height: 70px;
  border-radius: 10px;
}

.thead {
  display: flex;
  align-items: center;
}

.small_title {
  font-size: 13px;
  color: #7c7c7c;
  margin-top: 20px;
  margin-bottom: 10px;
}

.forms {
  width: 840px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.forms_item {
  width: 49.5%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ededed;
  padding:  5px 5px 5px 10px;
  margin-bottom: 10px
}

.forms_item2 {
  align-items: center;
  background: #ededed;
  padding: 5px  15px;
  margin-bottom: 10px
}

.forms_item3 {
  background: #ededed;
  padding: 5px 15px;
  margin-bottom: 10px
}

.left_title {
  letter-spacing: 2px;
  font-size: 14px
}

.buttom_btns {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 50%;
  margin: 0px auto;
  margin-top: 50px;
  margin-bottom: 50px
}

.save {
  margin-right: 30px
}

.tback {
  display: flex;
  justify-content: right;
  width: 90%;
  margin: 0px  auto;
}

.wenhao {
  font-size: 20px;
}

.anniuwenhao {
  padding: 0px;
  background-color: #ededed;
  border: 1px solid #ededed;
}

.addtimelist {
  margin-top: 10px;
  color: green;
  font-size: 14px;
  display: flex;
  align-items: center;
  cursor: pointer
}

::v-deep .el-tree-node__content:hover {
  background-color: #ededed;
}

::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {
  background-color: #41c3a8;
  border-color: #41c3a8;
}

::v-deep .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  background-color: #ffffff;
  border-color: #DCDFE6;
}

::v-deep .el-checkbox__inner:hover {
  border-color: #DCDFE6;
}

::v-deep .el-checkbox__input.is-focus .el-checkbox__inner {
  border-color: #DCDFE6;
}

::v-deep .el-tree-node:focus > .el-tree-node__content {
  background-color: #ededed;
}

::v-deep .el-tree-node__content {
  padding-left: 0 !important;
}

::v-deep .el-tree-node.is-expanded > .el-tree-node__children {
  padding-left: 38px;
}

::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  color: #606266;
}

::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #fdfeff;
}

.goods-imgs__tips {
  color: #b8b8b8;
  line-height: 1;
}

.fenxiao ::v-deep .el-input__inner {
  width: 100px;
  border-radius: 0;
}

.cen ::v-deep .el-input__inner {
  text-align: center;
}

.sel ::v-deep .el-input--medium .el-input__inner {
  padding: 0 20px 0 10px;
}

::v-deep .el-upload-list {
  display: none !important;
}

::v-deep .el-upload:focus {
  color: #000000;
}

.layui-word-aux {
  color: #999 !important;
  padding-left: 130px !important;
  line-height: 20px;
}
</style>
